package number_746;

import java.util.Arrays;

public class Solution {
    //从前往后；
    public int minCostClimbingStairs(int[] cost) {
        int[] costs = new int[cost.length + 1];
        costs = Arrays.copyOf(cost, cost.length + 1);
        int[] dp = new int[cost.length + 1];
        dp[0] = costs[0];
        dp[1] = costs[1];
        for (int i = 2; i <= cost.length; i++) {
            dp[i] = Math.min(dp[i - 1], dp[i - 2]) + costs[i];
        }
        return dp[cost.length];
    }

    //从后往前；
    public int minCost(int[] cost) {
        int f1 = 0, f2 = 0;
        for (int i = cost.length - 1; i >= 0 ; i--) {
            int f0 = Math.min(f1,f2) + cost[i];
            f2 = f1;
            f1 = f0;
        }
        return Math.min(f1, f2);
    }



    public static void main(String[] args) {
        new Solution().minCostClimbingStairs(new int[]{10, 15, 20});
    }
}
